#pragma once
#include <iostream>
#include <string>
#include <functional>
#include "Socket.hpp"
#include <memory>
#include "InetAddr.hpp"
#include "Util.hpp"
#include "Parser.hpp"
#include "Protocol.hpp"
#include "Logger.hpp"

class Reactor; // 不能用extern修饰：用来修饰变量或函数
using callback_t = std::function<std::string(const std::string &)>;
class Connection
{
public:
    virtual void Read() = 0;
    virtual void Write() = 0;
    virtual void Except() = 0;
    virtual ~Connection()
    {
    }

    int SockFd()
    {
        return _sockfd;
    }
    void SetSockfd(int sockfd)
    {
        _sockfd = sockfd;
    }

    void SetCallback(callback_t &cb)
    {
        _cb = cb;
    }

    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }

    int GetW()
    {
        return _wflag;
    }

protected:
    int _sockfd;
    callback_t _cb; // 回调，主要用于channel中
    Reactor *_owner;
    bool _wflag;
};



